import {
  BrowserRouter as Router,
  Redirect,
  Route,
  Switch,
} from "react-router-dom";
import Layout from "@/pages/Layout";
import Login from "@/pages/Login";
import { isAuth } from "./utils";
import { message } from "antd";
import AuthRoute from "./components/AuthRoute";

function App() {
  return (
    <Router>
      <div>
        <Switch>
          <Route path="/login" component={Login}></Route>
          <AuthRoute path='/home'>
            <Layout></Layout>
          </AuthRoute>
          <Route
            exact
            path="/"
            render={() => {
              //判断是否登录
              if (isAuth()) {
                return <Layout />;
              } else {
                //请先登录
                message.warning('请先登录')
                //未登录 去登录页
               return <Redirect to="/login" />;
              }
            }}
          ></Route>
        </Switch>
      </div>
    </Router>
  );
}

export default App;
